const {
	editUrl,
	listUrl,
} = require('@utils/util-apis')['templateUrl']
const {
	openTemplateDialog,
	removeTemplate,
} = require('./table-methods')

module.exports = function(templateComp) {
	let {
		tableComp,
	} = templateComp
	tableComp.datagrid({
		fit: true,
		fitColumns: true,
		rownumbers: true,
		singleSelect: true,
		scrollOnSelect: true,
		url: listUrl,
		toolbar: [{
			iconCls: 'icon-add',
			text: '新建',
			handler() {
				openTemplateDialog.call(templateComp, 'add')
			}
		}, '-', {
			iconCls: 'icon-edit',
			text: '修改',
			handler() {
				openTemplateDialog.call(templateComp, 'update')
			}
		}, '-', {
			iconCls: 'icon-search',
			text: '查看',
			handler() {
				openTemplateDialog.call(templateComp, 'detail')
			}
		}, '-', {
			iconCls: 'icon-remove',
			text: '删除',
			handler() {
				removeTemplate.call(templateComp)
			}
		}],
		columns: [
			[{
				field: 'id',
				title: 'ID',
				width: 10,
			}, {
				field: 'name',
				title: '模板名',
				width: 20
			}, {
				field: 'description',
				title: '描述',
				width: 50,
			}, {
				field: 'project_name',
				title: '所属项目名称',
				width: 20,
				formatter(value, row, index) {
					return value || "自定义"
				},
			}]
		],
	})
}